package com.tt.fashionWebSite.controller;

import com.tt.fashionWebSite.dto.*;
import com.tt.fashionWebSite.service.Ad_BillService;
import com.tt.fashionWebSite.service.Ad_ColorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.text.ParseException;
import java.util.List;
import java.util.Map;

@Controller
public class Ad_BillController {
    @Autowired
    private Ad_BillService ad_billService;

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/header/adBillCommon", method = RequestMethod.POST)
    public @ResponseBody
    JsonResponseDto<Integer> adminBill(HttpServletRequest request, @RequestBody HoaDonDto billDto) {
        return new JsonResponseDto<Integer>(ad_billService.adminBill(billDto));
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/header/adEditBillCommon", method = RequestMethod.POST)
    public @ResponseBody
    JsonResponseDto<Integer> adminEditBill(HttpServletRequest request, @RequestBody HoaDonDto billDto) {
        return new JsonResponseDto<Integer>(ad_billService.adminEditBill(billDto));
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/getBillCommon", method = RequestMethod.GET)
    public @ResponseBody
    JsonResponseDto<List<HoaDonFullDto>> getBillCommon(HttpServletRequest request) {
        return new JsonResponseDto<List<HoaDonFullDto>>(ad_billService.getBillCommon(), JsonResponseCode.SUCCESS);
    }

/*    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/header/updateStatusBillCommon/{maHD}/{finish}/{status}", method = RequestMethod.GET)
    public @ResponseBody
    JsonResponseDto<List<HoaDonDto>> updateStatusBillCommon(HttpServletRequest request, @PathVariable String maHD, @PathVariable String finish, @PathVariable String status) throws ParseException {
        return new JsonResponseDto<List<HoaDonDto>>(ad_billService.updateStatusBillCommon(maHD, finish, status), JsonResponseCode.SUCCESS);
    }*/

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/header/updateStatusBillCommon", method = RequestMethod.POST)
    public @ResponseBody
    JsonResponseDto<HoaDonDto> updateStatusBillCommon(HttpServletRequest request, @RequestBody HoaDonDto billDto) {
        return new JsonResponseDto<HoaDonDto>(ad_billService.updateStatusBillCommon(billDto), JsonResponseCode.SUCCESS);
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/header/getDataSortInBill/{name}/{updown}", method = RequestMethod.GET)
    public @ResponseBody
    JsonResponseDto<List<HoaDonFullDto>> getDataSortInBill(HttpServletRequest request, @PathVariable String name, @PathVariable String updown) throws ParseException {
        return new JsonResponseDto<List<HoaDonFullDto>>(ad_billService.getDataSortInBill(name, updown), JsonResponseCode.SUCCESS);
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/header/getDataSearchInBill", method = RequestMethod.GET)
    public @ResponseBody
    JsonResponseDto<List<HoaDonFullDto>> getDataSearchInBill(HttpServletRequest request) throws ParseException {
        String name = request.getParameter("name");
        String content = request.getParameter("content");
        return new JsonResponseDto<List<HoaDonFullDto>>(ad_billService.getDataSearchInBill(name, content), JsonResponseCode.SUCCESS);
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/header/getDateSearchInBill/{name}/{dateBegin}/{dateEnd}", method = RequestMethod.GET)
    public @ResponseBody
    JsonResponseDto<List<HoaDonFullDto>> getDateSearchInBill(HttpServletRequest request, @PathVariable String name, @PathVariable String dateBegin, @PathVariable String dateEnd) throws ParseException {
        return new JsonResponseDto<List<HoaDonFullDto>>(ad_billService.getDateSearchInBill(name,dateBegin, dateEnd), JsonResponseCode.SUCCESS);
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/header/getFinishTimeSearchInBill/{name}/{finish}/{time}/{dateBegin}/{dateEnd}", method = RequestMethod.GET)
    public @ResponseBody
    JsonResponseDto<List<HoaDonFullDto>> getFinishTimeSearchInBill(HttpServletRequest request, @PathVariable String name, @PathVariable String finish, @PathVariable String time, @PathVariable String dateBegin, @PathVariable String dateEnd) throws ParseException {
        return new JsonResponseDto<List<HoaDonFullDto>>(ad_billService.getFinishTimeSearchInBill(name, finish, time, dateBegin, dateEnd), JsonResponseCode.SUCCESS);
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/header/getStatusTimeSearchInBill/{name}/{status}/{time}/{dateBegin}/{dateEnd}", method = RequestMethod.GET)
    public @ResponseBody
    JsonResponseDto<List<HoaDonFullDto>> getStatusTimeSearchInBill(HttpServletRequest request, @PathVariable String name, @PathVariable String status, @PathVariable String time, @PathVariable String dateBegin, @PathVariable String dateEnd) throws ParseException {
        return new JsonResponseDto<List<HoaDonFullDto>>(ad_billService.getStatusTimeSearchInBill(name, status, time, dateBegin, dateEnd), JsonResponseCode.SUCCESS);
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/header/getFinish_StatusTimeSearchInBill/{finish}/{status}/{time}/{dateBegin}/{dateEnd}", method = RequestMethod.GET)
    public @ResponseBody
    JsonResponseDto<List<HoaDonFullDto>> getFinish_StatusTimeSearchInBill(HttpServletRequest request, @PathVariable String finish, @PathVariable String status, @PathVariable String time, @PathVariable String dateBegin, @PathVariable String dateEnd) throws ParseException {
        return new JsonResponseDto<List<HoaDonFullDto>>(ad_billService.getFinish_StatusTimeSearchInBill(finish, status, time, dateBegin, dateEnd), JsonResponseCode.SUCCESS);
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/header/getFinishSearchInBill/{name}/{finish}", method = RequestMethod.GET)
    public @ResponseBody
    JsonResponseDto<List<HoaDonFullDto>> getFinishSearchInBill(HttpServletRequest request, @PathVariable String name, @PathVariable String finish) throws ParseException {
        return new JsonResponseDto<List<HoaDonFullDto>>(ad_billService.getFinishSearchInBill(name, finish), JsonResponseCode.SUCCESS);
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/header/getStatusSearchInBill/{name}/{status}", method = RequestMethod.GET)
    public @ResponseBody
    JsonResponseDto<List<HoaDonFullDto>> getStatusSearchInBill(HttpServletRequest request, @PathVariable String name, @PathVariable String status) throws ParseException {
        return new JsonResponseDto<List<HoaDonFullDto>>(ad_billService.getStatusSearchInBill(name, status), JsonResponseCode.SUCCESS);
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/header/getFinish_StatusSearchInBill/{finish}/{status}", method = RequestMethod.GET)
    public @ResponseBody
    JsonResponseDto<List<HoaDonFullDto>> getFinish_StatusSearchInBill(HttpServletRequest request, @PathVariable String finish, @PathVariable String status) throws ParseException {
        return new JsonResponseDto<List<HoaDonFullDto>>(ad_billService.getFinish_StatusSearchInBill(finish, status), JsonResponseCode.SUCCESS);
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/getBillDetailCommon", method = RequestMethod.POST)
    public @ResponseBody
    JsonResponseDto<List<ChiTietHoaDonDto>> getBillDetailCommon(HttpServletRequest request) {
        return new JsonResponseDto<List<ChiTietHoaDonDto>>(ad_billService.getBillDetailCommon(), JsonResponseCode.SUCCESS);
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/getAllMemberBill", method = RequestMethod.GET)
    public @ResponseBody
    JsonResponseDto<List<ThongTinThanhVienDto>> getMemberInfor(HttpServletRequest request) {
        return new JsonResponseDto<List<ThongTinThanhVienDto>>(ad_billService.getMemberInfor(), JsonResponseCode.SUCCESS);
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/getAllBillCode", method = RequestMethod.GET)
    public @ResponseBody
    JsonResponseDto<List<HoaDonFullDto>> getAllOrderCode(HttpServletRequest request) {
        return new JsonResponseDto<List<HoaDonFullDto>>(ad_billService.getBillCommon(), JsonResponseCode.SUCCESS);
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/getAllProductDetailCodeInBill", method = RequestMethod.GET)
    public @ResponseBody
    JsonResponseDto<List<ChiTietSanPhamDto>> getAllProductDetailCodeInBill(HttpServletRequest request) {
        return new JsonResponseDto<List<ChiTietSanPhamDto>>(ad_billService.getAllProductDetailCodeInBill(), JsonResponseCode.SUCCESS);
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/toBillPage/{maHD}", method = RequestMethod.GET)
    public @ResponseBody
    ModelAndView toPageProductSize(HttpServletRequest request, @PathVariable String maHD, Map<String, Object> map) throws ParseException {
        map.put("maHD", maHD);
        return new ModelAndView("admin/ad-bill-edit");
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/editBill", method = RequestMethod.POST)
    public @ResponseBody
    JsonResponseDto<HoaDonDto> getBillInfoEdit(HttpServletRequest request, @RequestBody HoaDonDto billDto) {
        return new JsonResponseDto<HoaDonDto>(ad_billService.getBillInfoEdit(billDto), JsonResponseCode.SUCCESS);
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/registerBillEdit", method = RequestMethod.POST)
    public @ResponseBody
    JsonResponseDto<HoaDonDto> registerBillEdit(HttpServletRequest request, @RequestBody HoaDonDto billDto) {
        return new JsonResponseDto<HoaDonDto>(ad_billService.registerBillEdit(billDto), JsonResponseCode.SUCCESS);
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/getAllMemberInBill", method = RequestMethod.GET)
    public @ResponseBody
    JsonResponseDto<List<ThongTinThanhVienDto>> getAllMemberInBill(HttpServletRequest request) {
        return new JsonResponseDto<List<ThongTinThanhVienDto>>(ad_billService.getAllMemberInBill(), JsonResponseCode.SUCCESS);
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/bill_toGetData", method = RequestMethod.POST)
    public @ResponseBody
    JsonResponseDto<HoaDonDto> getDataId(HttpServletRequest request, @RequestBody HoaDonDto billDto) {
        return new JsonResponseDto<HoaDonDto>(ad_billService.getDataId(billDto), JsonResponseCode.SUCCESS);
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/bill_toGetMember", method = RequestMethod.POST)
    public @ResponseBody
    JsonResponseDto<ThongTinThanhVienDto> getMemberId(HttpServletRequest request, @RequestBody ThongTinThanhVienDto memberDto) {
        return new JsonResponseDto<ThongTinThanhVienDto>(ad_billService.getMemberId(memberDto), JsonResponseCode.SUCCESS);
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/deleteBillDetail", method = RequestMethod.POST)
    public @ResponseBody
    JsonResponseDto<List<ChiTietHoaDonDto>> getBillDetailInfoDelete(HttpServletRequest request, @RequestBody List<ChiTietHoaDonDto> lstBillDto) {
        return new JsonResponseDto<List<ChiTietHoaDonDto>>(ad_billService.getBillDetailInfoDelete(lstBillDto), JsonResponseCode.SUCCESS);
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/updateStatusBill/{id}/{status}", method = RequestMethod.POST)
    public @ResponseBody
    JsonResponseDto<HoaDonFullDto> updateStatusBill(HttpServletRequest request, @PathVariable String id, @PathVariable Long status) {
        return new JsonResponseDto<HoaDonFullDto>(ad_billService.updateStatusBill(id, status), JsonResponseCode.SUCCESS);
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/updatePaymentBill/{id}/{payment}", method = RequestMethod.GET)
    public @ResponseBody
    JsonResponseDto<HoaDonFullDto> updatePaymentBill(HttpServletRequest request, @PathVariable String id, @PathVariable Long payment) {
        return new JsonResponseDto<HoaDonFullDto>(ad_billService.updatePaymentBill(id, payment), JsonResponseCode.SUCCESS);
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/deleteBill/", method = RequestMethod.POST)
    public @ResponseBody
    JsonResponseDto<Integer> deleteBill(HttpServletRequest request, @RequestBody List<HoaDonDto> hoaDonDtos) {
        return new JsonResponseDto<Integer>(ad_billService.deleteBill(hoaDonDtos));
    }
}
